package 二分查找;

public class 寻找旋转排序数组中的最小值6 {
    //https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/description/
    public int findMin1(int[] nums) {
        int end = nums[nums.length - 1];
        int left = 0, right = nums.length - 1;
        while(left < right) {
            int mid = left + (right - left) / 2;
            if(nums[mid] > end) left = mid + 1;
            else right = mid;
        }
        return nums[left];
    }
    public int findMin(int[] nums) {
        int head = nums[0];
        if(head < nums[nums.length - 1]) return head;
        int left = 0, right = nums.length - 1;
        while(left < right) {
            int mid = left + (right - left) / 2;
            if(nums[mid] >= head) left = mid + 1;
            else right = mid;
        }
        return nums[left];
    }
}
